<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Simple
 *
 * @author Aquiles
 */
require_once 'Zend/Auth/Adapter/Interface.php';

class Zend_Auth_Adapter_Simple implements Zend_Auth_Adapter_Interface{
    
    private $_username;
    private $_password;

    public function __construct($username, $password)
    {
        $this->_username = $username;
        $this->_password = $password;
    }
    
    public function authenticate() {
        $user = Application_Model_Funcionario::getInstance()->getByUsername($this->_username,$this->_password);
        $code = null;
        $id = null;
        $mensagem ="";
        if(count($user) == 0 || !isset($user)){
            $code = Zend_Auth_Result::FAILURE;
            $mensagem = 'Usuário inválido';
        }else if(count($user) == 1){
            $code = Zend_Auth_Result::SUCCESS;
            $id = $user[0];
            $mensagem = 'Sucesso';
        }
        
        
         return new Zend_Auth_Result(
                    $code,
                    $id,
                    array($mensagem));
    }
}

?>
